﻿using System;
using QDT.Common;

namespace QDT.Core.Projects
{
    public class RefundException : Exception
    {
        public RefundException():base()
        {
            StatusCode = RefundException.Unknow;
        }

        public RefundException(string message):base(message)
        {
            StatusCode = RefundException.Unknow;
        }

        public RefundException(string message, Exception inner):base(message,inner)
        {
            StatusCode = RefundException.Unknow;
        }

        public RefundException(int statusCode,Project project)
        {
            StatusCode = statusCode;
            Project = project;
        }

        public RefundException(int statusCode)
            : this(statusCode, null)
        {
            
        }

        public int StatusCode { get; set; }

        public Project Project { get; set; }

        /// <summary>
        /// 未知的异常
        /// </summary>
        public const int Unknow = 0;

        /// <summary>
        /// Project不能存在
        /// </summary>
        public const int NotExistProject = 1;

        /// <summary>
        /// 还款方式无效
        /// </summary>
        public const int InvalidRepayment = 2;

        /// <summary>
        /// 无效的贷款项目状态
        /// </summary>
        public const int InvalidProjectStatus = 3;

        /// <summary>
        /// 非正常顺序还款
        /// </summary>
        public const int NonNormalRepayment = 4;

        /// <summary>
        /// 已经还款完成
        /// </summary>
        public const int HasReplsyCompleted = 5;

        /// <summary>
        /// 没有足够的还款金额
        /// </summary>
        public const int NotEnoughMoney = 6;


        public override string Message
        {
            get
            {
                switch(StatusCode) {
                    case NotExistProject:
                        return "项目不存在或者已经被删除.";
                    case InvalidRepayment:
                        return "无效的还款方式.";
                    case InvalidProjectStatus:
                        return "无效的贷款状态.";
                    case NonNormalRepayment:
                        return "非正常的还款顺序.";
                    case HasReplsyCompleted:
                        return "还款已经结束.";
                    case NotEnoughMoney:
                        return "没有足够的还款金额";
                    default:
                        return base.Message;
                }
            }
        }
    }
}
